package com.nc.mem.serial.graph.common;

import java.nio.ByteBuffer;
import java.util.Locale;

import com.nc.mem.serial.graph.GraphSerializer;


public class LocaleSerializer extends GraphSerializer {

	public static LocaleSerializer INSTANCE = new LocaleSerializer();

	@Override
	public void doRead(final ByteBuffer src, final Object obj) {

	}

	@Override
	public void doWrite(final ByteBuffer dest, final Object obj) {
		final Locale l = (Locale) obj;
		final StringSerializer ss = StringSerializer.INSTANCE;
		ss.writeNonRoot(dest, l.getCountry());
		ss.writeNonRoot(dest, l.getLanguage());
		ss.writeNonRoot(dest, l.getVariant());
	}

	@Override
	public Object instantiate(final ByteBuffer src) {
		final StringSerializer ss = StringSerializer.INSTANCE;

		return new Locale(ss.readNonRootString(src), ss.readNonRootString(src), ss.readNonRootString(src));
	}

}
